package com.wty.basic.reflect;

import org.junit.Test;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;

/**
 * @Author wangtengyu
 * @Create 2018-08-09-10:30
 */
public class FieldDemo {


    @Test
    public void test1() throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException, NoSuchFieldException {
        Class clazz=Class.forName("com.wty.basic.reflect.Student");
        Student student= (Student) clazz.getConstructor().newInstance();
        System.out.println(student.toString());
        //Field fields[]=clazz.getFields();
        Field field=clazz.getDeclaredField("phoneNum");
        field.setAccessible(true);
        field.set(student,"123456");
        System.out.println(student);

    }
}
